<!DOCTYPE html>
<html >

<head>

  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Advanced Survey Data Analysis &amp; Survey Experiments</title>
  <meta name="description" content="Advanced Survey Data Analysis &amp; Survey Experiments">
  <meta name="generator" content="bookdown 0.6 and GitBook 2.6.7">

  <meta property="og:title" content="Advanced Survey Data Analysis &amp; Survey Experiments" />
  <meta property="og:type" content="book" />
  
  
  
  <meta name="github-repo" content="davidjbarney/bookdown-stata" />

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="Advanced Survey Data Analysis &amp; Survey Experiments" />
  
  
  

<meta name="author" content="Brian F. Schaffner">


<meta name="date" content="2018-03-07">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  
  
<link rel="prev" href="matching-and-balancing.html">
<link rel="next" href="survey-experiments.html">
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />










<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="./">Advanced Survey Data Analysis & Survey Experiments</a></li>

<li class="divider"></li>
<li class="chapter" data-level="1" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i><b>1</b> Introduction</a></li>
<li class="chapter" data-level="2" data-path="models-for-limited-dependent-variables.html"><a href="models-for-limited-dependent-variables.html"><i class="fa fa-check"></i><b>2</b> Models for Limited Dependent Variables</a><ul>
<li class="chapter" data-level="2.1" data-path="models-for-limited-dependent-variables.html"><a href="models-for-limited-dependent-variables.html#logit"><i class="fa fa-check"></i><b>2.1</b> Logit</a></li>
<li class="chapter" data-level="2.2" data-path="models-for-limited-dependent-variables.html"><a href="models-for-limited-dependent-variables.html#ordinal-logit"><i class="fa fa-check"></i><b>2.2</b> Ordinal Logit</a></li>
<li class="chapter" data-level="2.3" data-path="models-for-limited-dependent-variables.html"><a href="models-for-limited-dependent-variables.html#multinomial-logit"><i class="fa fa-check"></i><b>2.3</b> Multinomial Logit</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="sampling.html"><a href="sampling.html"><i class="fa fa-check"></i><b>3</b> Sampling</a></li>
<li class="chapter" data-level="4" data-path="design-weights.html"><a href="design-weights.html"><i class="fa fa-check"></i><b>4</b> Design Weights</a></li>
<li class="chapter" data-level="5" data-path="post-stratification-weights.html"><a href="post-stratification-weights.html"><i class="fa fa-check"></i><b>5</b> Post-Stratification Weights</a></li>
<li class="chapter" data-level="6" data-path="item-scaling.html"><a href="item-scaling.html"><i class="fa fa-check"></i><b>6</b> Item Scaling</a><ul>
<li class="chapter" data-level="6.1" data-path="item-scaling.html"><a href="item-scaling.html#alpha"><i class="fa fa-check"></i><b>6.1</b> Alpha</a></li>
<li class="chapter" data-level="6.2" data-path="item-scaling.html"><a href="item-scaling.html#factor-analysis"><i class="fa fa-check"></i><b>6.2</b> Factor Analysis</a></li>
<li class="chapter" data-level="6.3" data-path="item-scaling.html"><a href="item-scaling.html#irt"><i class="fa fa-check"></i><b>6.3</b> IRT</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="matching-and-balancing.html"><a href="matching-and-balancing.html"><i class="fa fa-check"></i><b>7</b> Matching and Balancing</a><ul>
<li class="chapter" data-level="7.1" data-path="matching-and-balancing.html"><a href="matching-and-balancing.html#coarsened-exact-matching"><i class="fa fa-check"></i><b>7.1</b> Coarsened Exact Matching</a></li>
<li class="chapter" data-level="7.2" data-path="matching-and-balancing.html"><a href="matching-and-balancing.html#entropy-balancing"><i class="fa fa-check"></i><b>7.2</b> Entropy Balancing</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="panel-data.html"><a href="panel-data.html"><i class="fa fa-check"></i><b>8</b> Panel Data</a><ul>
<li class="chapter" data-level="8.1" data-path="panel-data.html"><a href="panel-data.html#reshaping-data"><i class="fa fa-check"></i><b>8.1</b> Reshaping Data</a></li>
<li class="chapter" data-level="8.2" data-path="panel-data.html"><a href="panel-data.html#panel-analysis"><i class="fa fa-check"></i><b>8.2</b> Panel Analysis</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="survey-experiments.html"><a href="survey-experiments.html"><i class="fa fa-check"></i><b>9</b> Survey Experiments</a></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Advanced Survey Data Analysis &amp; Survey Experiments</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="panel-data" class="section level1">
<h1><span class="header-section-number">Chapter 8</span> Panel Data</h1>
<p>We will use the 2010-2014 CCES Panel Data as an example to demonstrate some panel analysis techniques. You may download the survey from <a href="http://dx.doi.org/10.7910/DVN/TOE8I1">here</a>.</p>
<div id="reshaping-data" class="section level2">
<h2><span class="header-section-number">8.1</span> Reshaping Data</h2>
<p>The CCES data comes in “wide” format. That means that each row is an individual and their responses for each year of the survey are recorded across the dataset in columns. For example, the variable <code>CC10_308a</code> is the individual’s approval of President Obama in 2010, <code>CC12_308a</code> is the approval of Obama in 2012, and <code>CC14_308a</code> is the value of approval for 2014.</p>
<p>While there may be some value to having data appear in this format, it is necessary to change to “long” format in order to conduct panel analyses in Stata. Long format means that there is a separate observation for each individual in each year. Thus, what you would end up with for this panel dataset is three observations for each respondent (2010, 2012, and 2014) with one variable for each question that was asked in each of those years. In other words, instead of having <code>CC10_308a</code>, <code>CC12_308a</code>, and <code>CC14_308a</code>, you would want just a single <code>CC_308a</code>. You would then have a caseid variable that is unique to each respondent, and a year variable that indicates which year each variable applies to.</p>
<p>Once we understand some of the re-naming conventions, it is not particulalry difficult to re-shape the dataset so that it works in this form. The do-file below shows how we would do this with the wide-form panel data. The basic gist is that we would be subsetting the wide-form dataset into three different datasets: one for each wave (or year). We then rename the variables so that they will have the same variable names in each year (e.g. <code>CC_308a</code> instead of <code>CC10_308a</code>, <code>CC12_308a</code>, and <code>CC14_308a</code>).</p>
<div class="figure">
<img src="Images/longform.png" />

</div>
<p>Once you have your data set up in long form, you can tell Stata that it is in panel format. To do this, you use the <code>xtset</code> command and then follow that command first with the variable indicating each unique respondent and the variable indicating each time period.</p>
<pre><code>xtset caseid year</code></pre>
<p>However, in this case we want to specify to Stata that the time periods in our analysis happen every two years rather than every year. Thus, we can include an additional option to the above command to make this clear:</p>
<pre><code>xtset caseid year, delta(2)</code></pre>
</div>
<div id="panel-analysis" class="section level2">
<h2><span class="header-section-number">8.2</span> Panel Analysis</h2>
<p>Now that we have <code>xtset</code> the data, we can use the entire body of <code>xt</code> commands in Stata. To see what these include, you can type <code>help xt</code> into the command line in Stata. Note that most common regression models are avaiable in xt format (e.g. <code>xtreg</code>, <code>xtlogit</code>, <code>xtologit</code>, and so on).</p>
<p>Let’s say that we are interested in understanding whether people punish or reward the president for their own employment situation. In other words, we want to see whether the act of getting a job (or losing a job) affects how people evaluated President Obama during his term in office. The dependent variable we will use here is a question asking how much people approve of Obama (<code>CC308a</code>). Our key independent variable will be whether an individual states that they are employed full-time or unemployed (we will exclude other employment responses from this analysis).</p>
<p>We need to do a little re-coding to get started:</p>
<pre><code>recode employ  4=0 2/3=. 5/9=., gen(employed)
recode CC308a 1=3 2=2 3=1 4=0 5=., gen(obama_approval)</code></pre>
<p>The most basic way we might try to analyze this data is to take a difference-in-difference approach. Essentially, what we are attempting to discern is whether individuals whose employment situation changes from one wave to the next change their opinions of Obama at a different rate compared to those whose employment situation does not change.</p>
<p>We can do a fairly simple first cut at this analysis through a regression framework. The first thing we need to do is created a lagged version of the employment variable (i.e. whether the person was employed in the previous wave).</p>
<pre><code>gen lagged_employed=l1.employed</code></pre>
<p>Now, let’s run a simple regression where we interact employed with <code>lagged_employed</code>. For our dependent variable, we want to know the difference in approval from the previous time period (because we are comparing the differences between the difference in approval for each group). Since Stata knows we have panel data, we can specify that we want the difference as our dependent variable using the <code>d1.</code> operator. So:</p>
<pre><code>reg d1.obama_approval lagged_employed#employed
margins, over(lagged_employed employed)</code></pre>
<div class="figure">
<img src="Images/diff.png" />

</div>
<p>Using the <code>margins</code> command after the regression provides a very easy way of seeing how approval changes among each of the four groups. For example, there was a .07 point drop in approval among individuals who were unemployed in one time period and stayed unemployed in the next wave. By comparison, approval dropped .048 for those who moved from being unemployed to being employed. Given the size ot the standard errors for these means, there is no significant difference between the two groups. You can also compare people who had a job and lost it to those who had and kept a job. Again, there is no sigificant difference in approval for these groups.</p>
<p>The difference-in-difference approach is often not the most efficient estimation of the data. This is because it only uses information comparing one time period to the period immediately before it; however, we can also learn something from comparing across multiple time periods. Additionally, the difference-in-difference approach works with binary treatment variables, but it does not easily handle variables with gradations (i.e. income, partisanship, etc.).</p>
<p>Another approach is using panel regression with unit fixed effects. To do this in Stata, we take advantage of the <code>xtreg</code> command.</p>
<pre><code>xtreg obama_approval employed, fe</code></pre>
<div class="figure">
<img src="Images/fixedeffects.png" />

</div>
<p>The <code>, fe</code> options specifies a fixed effects model. Essentially, we are controlling for any time-invariant differences across individuals by taking this approach. The information being used to determine the effect of employment status on approval is only for individuals whose employment status changed at some point during the 3 waves. Based on this approach, employment status appears to be unrelated to approval for Obama (based on the coefficient for the employed variable).</p>
</div>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="matching-and-balancing.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="survey-experiments.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"google": false,
"weibo": false,
"instapper": false,
"vk": false,
"all": ["facebook", "google", "twitter", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"download": null,
"toc": {
"collapse": "subsection"
}
});
});
</script>

</body>

</html>
